package br.com.hectordufau.rpgiiidetmobile;

import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class TelaPrincipal extends Activity {
	
	private PersonagemAdapter tableRowAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.telaprincipal);
		try 
		{
			PersonagemManager pMgr = new PersonagemManager(getApplicationContext());
			ArrayList<Personagem> personagens = pMgr.getPersonagens(); 
			tableRowAdapter = new PersonagemAdapter(getApplicationContext(), R.layout.telaprincipal, personagens);
			setListAdapter(tableRowAdapter);
		} 
		catch (Exception ex) 
		{
			Log.e(ex.toString(), ex.toString());
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.telaprincipal, menu);
		return true;
	}
	
	@Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
		switch (item.getItemId())
        {
        case R.id.sair:
        	this.finish();
    		break;
        case R.id.sobre:
        	this.alertaSobre();
    		break;
        }
		
		return true;
    }
	
	private void alertaSobre() {
    	AlertDialog.Builder alerta = new AlertDialog.Builder(TelaPrincipal.this);
    	alerta.setTitle("Sobre o RPG 3D&T Mobile");
    	alerta.setIcon(R.drawable.iiidet);
    	alerta.setMessage("RPG 3D&T Mobile v1.0\n\nJogue e Divirta-se!");
    	alerta.setNeutralButton("OK", new DialogInterface.OnClickListener() {
    	      public void onClick(DialogInterface dialog, int which) {
    	          return;
    	      } }); 
    	alerta.show();
    }
	
	@Override
	public void onDestroy() {
    	super.onDestroy();
    }
}
